package com.atguigu.gulimall.order.listener;

import com.atguigu.common.to.mq.SeckillOrderTo;
import com.atguigu.gulimall.order.service.OmsOrderService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author ming
 * @create 2022/5/14
 * @description:
 */
@Slf4j
@Service
public class OrderSeckillListern {
    @Autowired
    private OmsOrderService orderService;
    @RabbitListener(queues = "order.seckill.order.queue")
    public void listenOrderQueue(SeckillOrderTo order, Channel channel, Message message) throws IOException {
        try {
            log.info("*********准备参加秒杀单详细信息*******************");
            orderService.createSeckillOrder(order);
            //手动调用支付宝收单

            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (Exception e) {
            channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
        }
    }
}
